import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

public class MoterInvokeHandler implements InvocationHandler {
    private Subject subject;
    public MoterInvokeHandler(Subject subject){
        this.subject = subject;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before");
        System.out.println("call" + method);
        Object object = method.invoke(subject,args);
        System.out.println("after");
        return object;
    }

    public static void main(String[] args) {
//        Subject subject  = new RealSubject();
//        InvocationHandler handler = new MoterInvokeHandler(subject);
//        Subject subject1 =
//                (Subject) Proxy.newProxyInstance(
//                        handler.getClass().getClassLoader(),
//                        subject.getClass().getInterfaces(),
//                        handler);
//        subject1.sayHello("hello");
    }
}
